/*
 * @Des: 
 * @Author: jin_yc
 * @Date: 2020-01-06 15:46:12
 * @LastEditor: jin_yc
 * @LastEditTime: 2022-04-11 14:50:34
 */
import './config/microapp/public-path'
import Vue from 'vue'
import Api from '@/config/api'
import { tsDvalue } from './config'
import VueI18n from 'vue-i18n'
import { initAsSubApp, initAsIndependentApp } from '@/microapp/util'


Vue.config.productionTip = false

//在install前注入环境变量
Object.assign(Vue.prototype, Api)

if (!window.__POWERED_BY_QIANKUN__) {
  initAsIndependentApp()
  render()
}

var instance = null

/**
 * @description: 初始化入口
 * 
 */
async function render(props = {}) {
  const { container } = props

  //toDo 为了保证环境变量注入完成，再加载路由
  const { setTs } = require('@/utils/request/sign')
  const store = require('@/store').default
  const install = require('@/utils/hooks/loadPlugins').default
  const router = require('@/router').default
  const App = require('@/App.vue').default

  Vue.use(install)
  await setTs()
  window.setInterval(() => {
    setTs()
  }, tsDvalue)

  Vue.use(VueI18n)

  const i18n = new VueI18n({
    locale: 'zh', // 设置语言,默认为中文
    messages: {
      zh: require('./assets/lang/zh'), //中文
      en: require('./assets/lang/en'), //英文
    },
  })

  instance = new Vue({
    router,
    store,
    i18n, 
    render: h => h(App)
  }).$mount('#app')
}


// /**
//  * @description: 第一次进入子应用后调用
//  *               将父应用传递的值挂载vue原型上
//  */
//  export async function bootstrap (props = {}) {
//   initAsSubApp(props)
// }


// /**
//  * @description: 每次进入入子应用后调用
//  *               第一次进入时会在boostrap方法完成后调用
//  */
// export async function mount (props = {}) {
//   await render(props)
// }


// /**
//  * @description: 每次切出子应用后调用
//  *               断开子应用的websocket连接并销毁Vue实例
//  */
// export async function unmount () {
//   const store = require('@/store').default
//   store.commit(CLEAN_WEBSOCKET_POOL)
//   if (instance) {
//     instance.$el.innerHTML = ''
//     instance.$destroy()
//     instance = null
//   }
// }
